package com.mm.dds.service.impl;

import com.mm.dds.mapper.CompanyListMapper;
import com.mm.dds.service.DdsTestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class DdsTestServiceImpl implements DdsTestService {

    @Autowired
    private CompanyListMapper companyListMapper;

    //获取全部公司信息
    @Override
    public List getCompanyList() {

        return companyListMapper.getCompanyList();
    }

    //增加新的公司信息
    @Override
    public void insertCompany(Map map) {

        companyListMapper.insertCompany(map);

    }

    //增加新的公司信息后新建相对应的数据库
    @Override
    public void createCompanyDb(String companyDbName) {

        companyListMapper.createCompanyDb(companyDbName);

    }

    //如上新增的数据库内新建模板表格
    @Override
    public void createCompanyDbTable(String company_info) {
        companyListMapper.createCompanyDbTable(company_info);
    }

    //删除指定公司
    @Override
    public void deleteCompanyById(int companyId) {
        companyListMapper.deleteCompanyById(companyId);
        String companyName = "company_"+companyId;
        companyListMapper.deleteCompanyDbByName(companyName);
    }

    //获取新增公司的id
    @Override
    public String selectLastCompanyId() {

        return "company_"+(((int)companyListMapper.selectLastCompanyId().get("id")));

    }
}
